package cn.rwklyd.ecommerce.config;

import cn.rwklyd.ecommerce.interceptor.LoginCheckInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration //配置类
//拦截器配置类
public class WebConfigInterceptor implements WebMvcConfigurer {

    @Autowired
    private LoginCheckInterceptor loginCheckInterceptor; //注入拦截器

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截所有请求, 放行login、register
        registry.addInterceptor(loginCheckInterceptor).addPathPatterns("/**").excludePathPatterns("/login", "/register");
    }
}
